#pragma once

#include "src/base/Timestamp_v2.h" // Using your Timestamp replacement
#include "src/net/Poller_v2.h"     // Use your new Poller.h path

#include <map> // For EPollPoller's own ChannelMap
#include <vector>

struct epoll_event;

namespace sola // Or your chosen namespace
{
namespace net {

class Channel;   // Forward declaration
class EventLoop; // Forward declaration
///
/// IO Multiplexing with epoll(4).
///
class EPollPoller : public Poller {
public:
    EPollPoller(EventLoop* loop);
    ~EPollPoller() override;

    sola::Timestamp poll(int timeoutMs, ChannelList* activeChannels) override;
    void            updateChannel(Channel* channel) override;
    void            removeChannel(Channel* channel) override;
    bool            hasChannel(Channel* channel) const override;

private:
    static const int kInitEventListSize = 16;

    // Helper function to convert epoll_ctl operation codes to strings (for logging)
    static const char* operationToString(int op);

    void fillActiveChannels(int          numEvents,
                            ChannelList* activeChannels); // Removed const for NDEBUG channel map access
    void update(int operation, Channel* channel);

    using EventList  = std::vector<struct epoll_event>;
    using ChannelMap = std::map<int, Channel*>; // EPollPoller now owns its ChannelMap

    int        epollfd_;
    EventList  events_;
    ChannelMap channels_; // Moved from base Poller to EPollPoller
};

} // namespace net
} // namespace sola